<% content_for :sitemap do %>
  <span class="current"><%= t("admin.overview") %></span>
<% end %>
<div class="toolbar">
  <div class="btn-group">
    <a href="/admin/site_configs" class="btn btn-secondary"><i class="fa fa-cogs"></i> <%= t("admin.site_configs.settings") %></a>
    <a href="/admin/plugins" class="btn btn-secondary"><i class="fa fa-plug"></i> <%= t("admin.menu.plugins") %></a>
    <a href="/admin/applications" class="btn btn-secondary"><i class="fa fa-cubes"></i> <%= t("admin.menu.applications") %></a>
    <a href="/sidekiq" class="btn btn-secondary" target="_blank"><i class="fa fa-tasks"></i> <%= t("admin.menu.background_jobs") %></a>
    <a href="/pghero" class="btn btn-secondary" target="_blank"><i class="fa fa-database"></i> <%= t("admin.menu.database") %></a>
    <a href="/exception-track" class="btn btn-secondary" target="_blank"><i class="fa fa-warning"></i> <%= t("admin.menu.exception_logs") %>...</a>
  </div>
</div>
<div class="alert alert-info">
  <%= t("admin.dashboard.boot_at_html", time: (l(Homeland.boot_at.in_time_zone(Time.zone), format: :long)) ) %> (<%= timeago Homeland.boot_at %>)
  <%= link_to icon_tag("power-off", label: t("admin.reboot")), main_app.reboot_admin_dashboards_path, data: { method: :post, confirm: "你确定要重启 Homeland 吗？", disable_with: "请求中..." }, class: "text-danger float-right" %>
</div>
<% if Setting.legecy_envs.any? %>
  <div class="alert alert-warning">
    <h4 class="alert-heading">Deprecated configuration detected</h4>
    <ul>
      <% Setting.legecy_envs.each do |key| %>
        <li>Deprecated <code><%= key %></code> use <code><%= Setting.legecy_env_instead(key) %></code> instead.</li>
      <% end %>
    </ul>
    <div>More about the configuration: <a href="https://homeland.ruby-china.org/docs/configuration/config-file/" target="_blank">Homeland Document</a></div>
  </div>
<% end %>
<div class="clearfix">
  <div class="flex items-center md:justify-between">
    <div id="user-stat">
      <div class="stat">
        <div class="total">0</div>
        <div class="name">
          <%= t("admin.dashboard.users_count") %>
          <span class="total-week" rel="twipsy" title="Weekly">+0</span>
          <span class="total-month" rel="twipsy" title="Monthly">+0</span>
          <span><%= t("common.statics_online_users_count", count: User.online_users_count) %></span>
        </div>
      </div>
    </div>
    <div id="topic-stat">
      <div class="stat">
        <div class="total">0</div>
        <div class="name">
          <%= t("admin.dashboard.topics_count") %>
          <span class="total-week" rel="twipsy" title="Weekly">+0</span>
          <span class="total-month" rel="twipsy" title="Monthly">+0</span>
        </div>
      </div>
    </div>
    <div id="reply-stat">
      <div class="stat">
        <div class="total">0</div>
        <div class="name">
          <%= t("admin.dashboard.replies_count") %>
          <span class="total-week" rel="twipsy" title="Weekly">+0</span>
          <span class="total-month" rel="twipsy" title="Monthly">+0</span>
        </div>
      </div>
    </div>
  </div>
  <div class="flex items-center md:justify-between">
    <div id="notification-stat">
      <div class="stat">
        <div class="total">0</div>
        <div class="name">
          <%= t("admin.dashboard.notifications_count") %>
          <span class="total-week" rel="twipsy" title="Weekly">+0</span>
          <span class="total-month" rel="twipsy" title="Monthly">+0</span>
        </div>
      </div>
    </div>
    <div id="comment-stat">
      <div class="stat">
        <div class="total">0</div>
        <div class="name">
          <%= t("admin.dashboard.comments_count") %>
          <span class="total-week" rel="twipsy" title="Weekly">+0</span>
          <span class="total-month" rel="twipsy" title="Monthly">+0</span>
        </div>
      </div>
    </div>
    <div id="photo-stat">
      <div class="stat">
        <div class="total">0</div>
        <div class="name">
          <%= t("admin.dashboard.photos_count") %>
          <span class="total-week" rel="twipsy" title="Weekly">+0</span>
          <span class="total-month" rel="twipsy" title="Monthly">+0</span>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript">
    function updateStatValue(data) {
      var el = $('#' + data.model + '-stat');
      el.find(".total").text(data.count);
      el.find(".total-week").text('+' + data.week_count);
      el.find(".total-month").text('+' + data.month_count);
    }
    
    var models = ['user', 'topic', 'reply', 'notification', 'photo', 'comment'];
    for (var i = 0; i < models.length; i ++) {
      var model = models[i];
      $.get("/admin/stats?model="+ model +"&by=month", function(data) {
        updateStatValue(data)
      });
    }
  </script>
</div>
